using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using XDQ.VAT.Students;
using XDQ.VAT.Students.Dtos;
using XDQ.VAT.Web.Pages.Students.AppStudent.ViewModels;

namespace XDQ.VAT.Web.Pages.Students.AppStudent
{
    public class CreateModalModel : VATPageModel
    {
        [BindProperty]
        public CreateEditAppStudentViewModel ViewModel { get; set; }

        private readonly IAppStudentAppService _service;

        public CreateModalModel(IAppStudentAppService service)
        {
            _service = service;
        }

        public virtual async Task<IActionResult> OnPostAsync()
        {
            var dto = ObjectMapper.Map<CreateEditAppStudentViewModel, CreateUpdateAppStudentDto>(ViewModel);
            await _service.CreateAsync(dto);
            return NoContent();
        }
    }
}